#include<iostream>
using namespace std;
const int N=1e3+10;
struct books{
    bool flag;
	int hh,mm;
	books(){
		flag=0;
	}	
}; 
int n;
int main()
{
    cin>>n;
    while(n--)
    {
    	books p[N];
        int id,h,m;
        int cnt=0,sum=0;
        string op;
        while(1)
        {
        	cin>>id>>op;
			scanf("%d:%d",&h,&m);
        	if(!id)
        	break;
        	if(op[0]=='S')
        	{
        		p[id].hh=h;
        		p[id].mm=m;
        		p[id].flag=1;
			}
			else if(op[0]=='E'&&p[id].flag)
			{
				cnt++;
				sum=sum+h*60+m-p[id].hh*60-p[id].mm;
				p[id].flag=0;
			}
		}
		if(cnt)
		printf("%d %.0lf\n",cnt,(double)sum/cnt);
		else
		cout<<"0 0"<<endl;
    }
    return 0;
}
